package com.ld.poetry.dao;

import com.ld.poetry.entity.Comment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ld.poetry.vo.CommentVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; // 导入 Page 类
import java.util.List;

/**
 * <p>
 * 文章评论表 Mapper 接口
 * </p>
 *
 * @author sara
 * @since 2021-08-13
 */
public interface CommentMapper extends BaseMapper<Comment> {

    // 修改为支持分页查询
    @Select("SELECT DISTINCT c.* FROM comment c " +
            "LEFT JOIN im_chat_user_friend f ON (c.user_id = f.friend_id OR c.user_id = f.user_id) " +
            "WHERE (c.user_id = #{userid} OR (f.user_id = #{userid} OR f.friend_id = #{userid}) AND f.friend_status = 1)")
    List<Comment> selectCommentsWithFriend(Page<Comment> page, @Param("userid") Integer userid);
}
